<?php
// The web path directory
defined('WEB_PATH') || define('WEB_PATH', dirname(__FILE__));
// The root path directory
defined('ROOT_PATH') || define('ROOT_PATH', dirname(WEB_PATH));
// Define path to configs path
defined('CONFIG_PATH') || define('CONFIG_PATH', realpath(ROOT_PATH . '/config'));
// Define path to library directory
defined('LIBRARY_PATH') || define('LIBRARY_PATH', realpath(ROOT_PATH . '/library'));
// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(ROOT_PATH . '/application'));
// tmp path
defined('DATA_PATH') || define('DATA_PATH', realpath(ROOT_PATH . '/data'));

/* __autoload rewrite */
spl_autoload_register(function($className){
    $_file = LIBRARY_PATH . "/" . str_replace('\\', '/', $className) .".php";
    if (file_exists($_file)) {
        require $_file;
    }
});
if (!is_dir(DATA_PATH."/caches"))\wodrow\tools\Tools::createDir(DATA_PATH."/caches");
if (!is_dir(DATA_PATH."/session"))\wodrow\tools\Tools::createDir(DATA_PATH."/session");
if (!is_dir(DATA_PATH."/logs"))\wodrow\tools\Tools::createDir(DATA_PATH."/logs");
if (!is_dir(DATA_PATH."/tmp"))\wodrow\tools\Tools::createDir(DATA_PATH."/tmp");
if (!is_dir(DATA_PATH."/backup"))\wodrow\tools\Tools::createDir(DATA_PATH."/backup");
spl_autoload_register(function($className){
    $_file = ROOT_PATH . "/" . str_replace('\\', '/', $className) .".php";
    if (file_exists($_file)) {
        require $_file;
    }
});
require_once ROOT_PATH."/api_vendor/php_api_sdk/loader.php"; // add api vendor
/* autoload end */

/**
 * wodrow lib
 */
$app = new \wodrow\site\App();
$app->run();
/* wodrow lib end */

//Global
include CONFIG_PATH . '/Global.php';

//__autoload
/*function __autoload($Class) {
    if (file_exists(LIBRARY_PATH . '/' . $Class . '.php')) {
        include LIBRARY_PATH . '/' . $Class . '.php';
    }
    return false;
}*/

//zip
if (IS_ZIP != false && XML_R == false) {
    if (strstr($_SERVER['HTTP_USER_AGENT'], 'compatible') && ob_start('compress')) {
        header('Content-Encoding: gzip');
    } else if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && ob_start('ob_gzhandler')) {
        header('Content-Encoding: gzip');
    } else {
        ob_start();
    }
} else {
    ob_start();
}
//Controller
include CONFIG_PATH . '/Controller.php';
ob_end_flush();